<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>show</title>
    <script src="${pageContext.request.contextPath}/static/js/jquery-3.0.0.min.js"></script>
</head>
<body>
    <table border="1" cellspacing="0" width="400px" height="400px">
        <thead>
            <tr>
                <th>编号</th>
                <th>名称</th>
                <th>类型</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            <c:forEach items="${list}" var="code">
                <tr>
                    <td>${code.cid}</td>
                    <td>${code.cname}</td>
                    <td>${code.ctype}</td>
                    <td>
                        <button id="del" >删除</button>
                        <a href="update/${code.cid}">修改</a>
                    </td>
                </tr>
                <c:set var="cid" value="${code.cid}" scope="page"></c:set>
            </c:forEach>
        </tbody>
    </table>
    <a href="${pageContext.request.contextPath}/update">添加</a>
    <script>
        $(function () {
           $("#del").click(function(){
                alert("Hello") ;
                  $.ajax({
                      url:"${pageContext.request.contextPath}/code/${cid}",
                      type:"post",
                      data:{"_method":"delete"},
                      dataType:"json",
                      success:function (param) {
                          if(param.success){
                              window.location="${pageContext.request.contextPath}/list";
                          }else{
                              console.log(param.msg);
                          }

                      }
                  })
           })
        })
    </script>
</body>
</html>
